home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / RTF / view.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  150 lines

  1. /* $Header: /usr/people/pcd/Src/RTF/RCS/view.h,v 1.1 92/11/23 12:58:53 pcd Exp Locker: pcd $
  2.  */
  3.  
  4. #ifndef __view_h
  5. #define __view_h
  6.  
  7. #include "textflow.h"
  8. #include "textrect.h"
  9. #include "elements.h"
  10. #include "rtftoken.h"
  11.  
  12. class RTFPos : public RTF{
  13. public:
  14.   RTFPos(const char* text)
  15.     { start_ = end_ = 0; p = text;};
  16.  
  17.   TextPosition start()
  18.     { return start_; };
  19.  
  20.   TextPosition end()
  21.     { return end_; };
  22.  
  23.   void getText();
  24.  
  25.   void getHex();
  26.  
  27. protected:
  28.   void _GetToken()
  29.     { start_ = end_;
  30.       RTF::_GetToken();
  31.       if(CheckCMM(Control, PictAttr, PicBinary)) //@# need this?
  32.         end_ +=Param();
  33.     };
  34.  
  35.   int next_char()
  36.     { end_++; return *p++; }
  37.  
  38.   void pushback(int)
  39.     { p--; end_--; };
  40.  
  41. private:
  42.   TextPosition start_, end_;
  43.   const char* p;
  44. };
  45.  
  46.  
  47.  
  48. class View{
  49. public:
  50.   View();
  51.   ~View();
  52.  
  53.   virtual unsigned long color(int , int, int) const
  54.     { return 0; };
  55.  
  56.   virtual Coord hinches(double inches) const
  57.     { return (Coord)inches; }
  58.   virtual Coord vinches(double inches) const
  59.     { return (Coord)inches; };
  60.   virtual void text_flow(TextFlow&, TextPosition, TextPosition,
  61.              const CharacterFormat&)
  62.     {};
  63.   virtual void text_char(TextFlow&, TextPosition, TextPosition, char,
  64.              const CharacterFormat&)
  65.     {};
  66.   virtual void new_line(TextFlow&, TextPosition, TextPosition,
  67.             Inches)
  68.     {};
  69.   virtual void picture(TextFlow&, TextPosition, TextPosition,
  70.                Coord, Coord)
  71.     {};
  72.  
  73.   void parse_text(RTFPos&, TextFlow&, const CharacterFormat&);
  74.  
  75.   TextFlow* ASCII(const char* data, Qty q);
  76.   TextFlow* RichText(const char* data, Qty q);
  77.   static char*     plain_text(const char* rich_text, Qty q);
  78.  
  79.   int         string(const char*, int);
  80.   /* USE : view->string(char* data, rtf)
  81.    *       return 0 on errors
  82.    *****************/
  83.  
  84.   int         resize(BRect);
  85.   int         resize(Coord x, Coord y, Coord w, Coord h)
  86.     { BRect b(x, y, w, h);
  87.       return resize(b); };
  88.  
  89.   int         range(TextPosition, TextPosition);
  90.  
  91.   Coord       page_height()
  92.     { return format() ? bounds().height() : 0; };
  93.  
  94.   Coord       height() const
  95.     { return bounds().height(); };
  96.   Coord       width() const
  97.     { return bounds().width(); };
  98.  
  99.   TextPosition position(Coord x, Coord y)
  100.     { return page_ ? page_->position(x,y) : 0; }; //@@ default answer 0?
  101.  
  102.   TextPosition first() const
  103.     { return first_; };
  104.   TextPosition last() const
  105.     { return last_; };
  106.  
  107.   const BRect& bounds() const
  108.     { return bounds_; };
  109.  
  110. protected:
  111.   virtual void clear()
  112.     {};
  113.   int          format();
  114.   void         unformat();
  115.  
  116.   void parse_picture(RTFPos&, TextFlow&);
  117.  
  118.   TextFlow* flow_;
  119.   TextRect* page_;
  120.   BRect     bounds_;
  121.   TextPosition first_, last_;
  122. };
  123.  
  124.  
  125. class RTFCharacterFormat : public CharacterFormat{
  126. public:
  127.   RTFCharacterFormat(RTFCharacterFormat* p)
  128.     { if(p) *this = *p; parent_ = p; };
  129.  
  130.   RTFCharacterFormat* parent()
  131.     { return parent_; };
  132.  
  133.   RTFCharacterFormat* pop()
  134.     { RTFCharacterFormat* r = parent_;
  135.       if(r) {
  136.     delete this; return r;
  137.       }  else return this;
  138.     };
  139.  
  140.   void set_attr(int attr, int val);
  141.  
  142.   char* spec();
  143.  
  144. private:
  145.   RTFCharacterFormat* parent_;
  146. };
  147.  
  148.  
  149. #endif
  150.